<template>
  <!-- 大客户线索管理->线索分配 -->
  <div>
    <!-- 搜索 -->
     <TopFilter  :list="topFilterInit"  :cols="3"  labelWidth="100"  @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
     <!-- table -->
    <FilterTable   ref="table" :columns="columns"   :fetchapi="fetchParams" :params="flterValue" :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns">
      <template slot="controls" >
        <el-button size="small" type="primary" icon="el-icon-plus" @click="distributionHandle">分配</el-button>
      </template>
   </FilterTable>
   <!-- 新增弹窗 -->
  <Drawer   title="大客户区域经理查询" :visible.sync="visible"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}" >
      <distribution-madal  ref="addDialog" @close="closeHandler" />
   </Drawer>
   <Drawer  :visible.sync="visibleDrawer"
      title="线索分配明细"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <info-modal  v-model="infoId" @close="infoClose" />
   </Drawer>
  </div>
</template>
<script>
import distributionMadal from './distributionMadal'
import infoModal from '../createClue/info'
import { dictionary } from '@/utils/dictMixin';
import { PHONE_PATTERN } from '@/utils/validate' // 验证
export default {
  name: 'customerAdd',
  mixins: [dictionary],
  components: {
    distributionMadal,infoModal
  },
  data() {
    return {
      visible:false,
      visibleDrawer:false,
      infoId:null,
      topFilterInit:this.topFilterInitFun(),
      flterValue:{},  //参数
      columns:this.creatHeader(),
      fetchParams:null, //ipa 接口
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
      //搜索数据
      topFilterInitFun(){
        return [
            { type: 'INPUT',   label: '客户公司名称', fieldName: 'field1', placeholder: '请输入',initialValue: '' },
            { type: 'SELECT',  label: '客户类型',  fieldName: 'field2',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1008') },
            { type: 'SELECT',  label: '客户性质', fieldName: 'field3',   placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1008') },
            { type: 'INPUT',   label: '省份',    fieldName: 'field4',  placeholder: '请输入',  initialValue: ''},
            { type: 'SELECT',  label: '客户状态', fieldName: 'field5',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1008') },
            { type: 'SELECT',  label: '客户来源', fieldName: 'field6',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1008') },
            { type: 'SELECT',  label: '分配状态', fieldName: 'field9',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1008') },
            { type: 'INPUT',   label: '客户关键联系人', fieldName: 'field7', placeholder: '请输入',initialValue: '' },
            { type: 'INPUT',   label: '联系电话', fieldName: 'field8', placeholder: '请输入',initialValue: '',
              rules: [{ pattern: PHONE_PATTERN, message: '手机格式不正确', trigger: 'blur' }] }
        ]
      },
      //搜索获取数据
      changeHandle(val){
          this.flterValue=val
          console.log(val)
      },
      //table表头和数据源
      creatHeader(){
         return [
         {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
         },
         {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>明细</el-button>
              </div>
            );
          }
        },
        { title: '分配状态',  dataIndex: 'field0', sorter: true},
        { title: '客户公司名称',  dataIndex: 'field1', sorter: true},
        { title: '客户类型',      dataIndex: 'field2', sorter: true},
        { title: '指定区域经理',   dataIndex: 'field3', sorter: true},
        { title: '客户性质',    dataIndex: 'field4',  sorter: true},
        { title: '所在省',  dataIndex: 'field5',   sorter: true},
        { title: '所在市',  dataIndex: 'field6', sorter: true},
        { title: '所在县/区',  dataIndex: 'field7',   sorter: true },
        { title: '详细地址',  dataIndex: 'field8',  sorter: true},
        { title: '客户状态',  dataIndex: 'field9', sorter: true,
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }},
        { title: '客户来源',  dataIndex: 'field91',  sorter: true,
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }},
        { title: '所属行业分类',  dataIndex: 'field10',  sorter: true },
        { title: '行业地位', dataIndex: 'field11',sorter: true },
        { title: '购车用途',  dataIndex: 'field12',  sorter: true},
        { title: '预计采购日期',  dataIndex: 'field13',  sorter: true },
        { title: '客户采购方式', dataIndex: 'field14', sorter: true },
        { title: '预算来源',  dataIndex: 'field15',  sorter: true },
        { title: '客户关键采购人',  dataIndex: 'field16',  sorter: true},
        {title: '联系方式',  dataIndex: 'field17',  sorter: true}
        ]
      },
      // 分配窗口 -传数据
      distributionHandle(){
        this.visible=true
      },
      // 分配关闭窗口 -返回数据
      closeHandler(data){
      this.visible=data.visible //关闭弹窗
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    //详情
    detailHandle(row){
      this.infoId=1001  //行id
      this.visibleDrawer=true
    },
    //关闭详情
    infoClose(){
      this.visibleDrawer=false
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
     collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
